﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Protocol.Interface
{
    /// <summary>
    /// 异步客户端
    /// </summary>
    public interface IAsyncClient
    {
        /// <summary>
        /// 连接状态
        /// </summary>
        bool Connected { get; }
        /// <summary>
        /// 异步连接
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="times">重连次数</param>
        /// <returns>连接状态</returns>
        Task<bool> ConnectAsync(string ip, int port, int times = 5);
        /// <summary>
        /// 异步连接,地址示例:127.0.0.1:12450
        /// </summary>
        /// <param name="address">完整的地址</param>
        /// <param name="times">重连次数</param>
        /// <returns>连接状态</returns>
        Task<bool> ConnectAsync(string address, int times = 5);

        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="msg">字符串</param>
        /// <returns>发送结果</returns>
        bool Send(string msg);
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="msg">字符串</param>
        /// <param name="encoding">编码,默认ASCII</param>
        /// <returns>发送结果</returns>
        bool Send(string msg, Encoding encoding);
        /// <summary>
        /// 发送数据
        /// </summary>
        /// <param name="buffer">字节集</param>
        /// <returns>发送结果</returns>
        bool Send(byte[] buffer);
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="result">数据</param>
        /// <returns></returns>
        bool Read(ref string result);
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="result">数据</param>
        /// <param name="encoding">编码,默认ASCII</param>
        /// <returns></returns>
        bool Read(ref string result, Encoding encoding);
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="byte_receive">接收的字节集</param>
        /// <returns>接收的字节集长度</returns>
        int Read(ref byte[] byte_receive);
        /// <summary>
        /// 断开连接
        /// </summary>
        void DisConnect();
        /// <summary>
        /// 连接状态改变通知事件
        /// </summary>
        event PropertyChangedEventHandler PropertyChanged;
    }
}
